package com.ht.medicaltreatment.viewmodel

import androidx.lifecycle.viewModelScope
import com.ht.medicaltreatment.bean.CentrifugeAddBean
import com.ht.medicaltreatment.bean.RfidSample
import com.xgst.lib.http.ApiResult
import kotlinx.coroutines.launch

class SampleScanViewModel : BaseViewModel() {
    //扫描功能，根据rfid编号查询样本
    fun scanOfRfid(stopCentrifugeId :String, onSuccess:(MutableList<RfidSample>?)->Unit, onError:(String)->Unit){
        viewModelScope.launch {
            val bean = mApi.scanOfRfid(stopCentrifugeId)
            when(bean){
                is ApiResult.Success -> onSuccess(bean.data.data?.rfidSampleList)
                is ApiResult.Error -> onError(bean.errorMessage)
            }
        }
    }

    //把样本添加到离心样本表中
    fun addCentrifuge(sampleArrId: String, centrifugeId:String, onSuccess:(CentrifugeAddBean?)->Unit, onError:(String)->Unit){
        viewModelScope.launch {
            val bean = mApi.addCentrifuge(sampleArrId,centrifugeId)
            when(bean){
                is ApiResult.Success -> onSuccess(bean.data.data)
                is ApiResult.Error -> onError(bean.errorMessage)
            }
        }
    }
}
